package databaseComm;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import results.IncorrectProblemStatistic;
import results.Result;
import accounts.Account;
import accounts.Admin;
import accounts.Instructor;
import accounts.Student;
import equations.Addition;
import equations.Division;
import equations.FractionToDecimal;
import equations.MathFactsCategory;
import equations.Multiplication1;
import equations.Multiplication2;
import equations.Problem;
import equations.Subtraction;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JOptionPane;
/**
 * This is the stubbed database API
 * @author stewarte
 *
 */
public class DatabaseAccessAPIStub implements DatabaseDriverInterface{

	static String dbDriver = "";
	static String dbUrl = "";
	static Connection connection = null;
	private Statement statement = null;


	public DatabaseAccessAPIStub(String address, String dbDriver, String login, String password){
		dbUrl = address;
		this.dbDriver = dbDriver;
		connectToDatabase(login,password);
		try {
			statement = connection.createStatement();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void exitConnection() {

		try{
			
			if(statement != null) {
//				statement.close();
			}
			//try to close the db connection
			connection.close();
		} catch(SQLException e) {
			JOptionPane.showMessageDialog(null, e.getMessage());
		}

	}

	@Override
	public  boolean connectToDatabase(String username, String password) {

		try{
			Class.forName(dbDriver);
		}catch(ClassNotFoundException e) {
			JOptionPane.showMessageDialog(null, "Jdbc not found");
			System.exit(0);
		}


		int counter  = 0;

		//try until it does not connect
		while(counter < 10000) {
			try {

				//get the connection by supplying login, password and url with database name
				connection = DriverManager.getConnection(dbUrl, username, password);
				connection.setClientInfo("autoReconnect","true");
				JOptionPane.showMessageDialog(null, "Connection Passed");
				return true;
			}catch(SQLException e) {
				JOptionPane.showMessageDialog(null,e.getMessage());
			}
			counter++;
		}

		return false;
	}

	@Override
	public Account authenticateLogin(String username, String password) {
		//these are the stubbed accounts
		Account retVal=null;
		if(!this.usernameAvailable(username)) {
			
			ResultSet result = null;


			String queryPassword = "select password from users where login_name = '" + username + "'";

			try {
				
				result = statement.executeQuery(queryPassword);
				String passwordObtained = "";
				if(result.next()) {
					passwordObtained = result.getString("password");

				}



				if(!passwordObtained.equals(password)) {

					return retVal;
				}
			}catch(SQLException e) {
				e.getMessage();
			}finally {
				try {
					
					if(result != null) {
						result.close();
					}
					
				}catch(SQLException e) {
					e.getMessage();
				}
			}


			String query = "select user_id from users where login_name = '" + username + "'";
			String query1 = "";
			String query2 = "";



			try {

				statement = connection.createStatement();
				result = statement.executeQuery(query);

				int user_id = -1;
				if(result.next()) {
					user_id = result.getInt("user_id");
				}

				if(user_id != -1) {
					query1 = "select privileges_id from users_has_privileges where user_id = '" + user_id + "'";
				}

				result = statement.executeQuery(query1);
				int privileges_id = -1;
				if(result.next()) {
					privileges_id = result.getInt("privileges_id");
				}

				query2 = "select fname, lname from users where login_name = '" + username + "'";

				result = statement.executeQuery(query2);
				String fName = "";
				String lName = "";

				if(result.next()) {
					fName = result.getString("fName");
					lName = result.getString("lName");
				}

				//we should base this if block based on the account type.
				if(privileges_id == 2){
					retVal = new Instructor(username,password,fName,lName);
				}else if(privileges_id == 3){
					retVal = new Student(username,password,fName,lName);
				}else if(privileges_id == 1){
					retVal = new Admin(username, password, fName, lName);
				}


			}catch(SQLException e) {
				e.printStackTrace();
			} finally {
				try {
					
					if(result != null) {
						result.close();
					}
					
				} catch (SQLException e) {

					e.getMessage();
				}

			}


		}
		return retVal;
	}

	@Override
	public boolean createAccount(Account creator, Account toBeCreated) {

		//:We would dissect the account to be created and add it to the database appropriately.
		//to do this, we get the instance of the toBeCreated object, this tells us the account type
		//then we get the username, password, and first and last name information from toBeCreated
		//and add it as a row to the database

		//only create an account if we are an admin
		if(creator instanceof Admin){

			String loginName = toBeCreated.getUserName();
			String password = toBeCreated.getPassword();
			String firstName = toBeCreated.getFirstName();
			String lastName = toBeCreated.getLastName();
			String query= "insert into users (login_name, password, fname,lname) values('"+loginName +"','" + password + "','" + firstName + "','" + lastName + "')";
			String query1 = "select user_id from users where login_name ='"+ loginName+"'";


			ResultSet result = null;
			int privilege_id = 3;

			if(toBeCreated instanceof Admin) {
				privilege_id = 1;
			} else if(toBeCreated instanceof Instructor) {
				privilege_id = 2;
			} else if(toBeCreated instanceof Student) {
				privilege_id = 3;
			}
			try{

				statement.executeUpdate(query);
				result = statement.executeQuery(query1);

				while(result.next()) {
					int user_id  = result.getInt("user_id");
					String query2 = "insert into users_has_privileges (user_id, privileges_id) values ( '" + user_id + "' , '" + privilege_id + "')";
					statement.executeUpdate(query2);
				}
			}catch(SQLException e){
				e.getMessage();
			}

			finally{
				try {
					if(result != null) {
						result.close();
					}
				} catch (SQLException e) {

					e.getMessage();
				}
			}
			return true;
		}
		return false;
	}


	@Override
	public String retrievePassword(Account retriever, String username) {

		String query = "select password from users where login_name = '" + username + "'";
		String password = null;

		
		ResultSet result = null;

		try{
			
			result = statement.executeQuery(query);

			if(result.next()){

				password = result.getString("password");
			}
		}catch (SQLException e){
			e.getStackTrace();
		}finally{
			try {
				
				if(result != null) {
					result.close();
				}
			} catch (SQLException e) {

				e.getMessage();
			}
		}
		return password;
	}

	// This is mine
	// It is Done and tested
	// I added correct instead of countIncorrect to the database. ///////////// READ THIS //////////
	// Also, I create the time here because there is difference in the format of Time and Date
	// between Java and SQL. Therefore, I used the Now() function that create the date and time
	// automatically in the SQL.
	@Override
	public boolean addResult(Result r) {
		//TODO: Add the result to the database, result has 
		//countIncorrect,totalquestions,username,mathfactscategory,and date
		//use these to fill in a row in the table.		

		boolean flag = false;
		
		ResultSet result = null;

		int correct = -1;
		Date date = null;
		int total = -1;
		String userName = null;
		int category_id = -1;

		correct = r.getCountCorrect();
		date = r.getCompletionDate();
		total = r.getTotalQuestions();
		userName = r.getUserName();

		if( r.getResultCategory().equalsIgnoreCase("Addition")){
			category_id = 1;
		}else if( r.getResultCategory().equalsIgnoreCase("Subtraction")){
			category_id = 2;
		}else if( r.getResultCategory().equalsIgnoreCase("Multiplication I")){
			category_id = 3;
		}else if( r.getResultCategory().equalsIgnoreCase("Multiplication II")){
			category_id = 4;
		}else if( r.getResultCategory().equalsIgnoreCase("Division")){
			category_id = 5;
		}else if( r.getResultCategory().equalsIgnoreCase("Fractions to Decimals")){
			category_id = 6;
		}

		if(correct != -1 && date != null && total != -1 && userName != null && category_id != -1){



			String query = "insert into results (correct, date, total,category_id) values (" + correct + ", Now() ," + total + ","+ category_id +")";
			String query1 = "select user_id from users where login_name = '" + userName +"'";
			String query2 = "select max(result_id) from results";
			int result_id = -1;

			try{

				
				statement = connection.createStatement();
				statement.executeUpdate(query);

				result = statement.executeQuery(query2);
				if(result.next()){
					result_id = result.getInt("max(result_id)");
				}

				result = statement.executeQuery(query1);
				int user_id = -1;
				if(result.next()){
					user_id = result.getInt("user_id");
				}
				if(user_id != -1 && result_id != -1){

					String query3 = "insert into users_has_results (user_id, result_id) values ("+ user_id +","+ result_id+ ")";
					statement.executeUpdate(query3);

					flag = true;
				}

			}catch(SQLException e){
				e.printStackTrace();

			}finally {
				try {
					if(statement != null && result != null) {
						
						result.close();
					}
				}catch(SQLException e) {
					e.printStackTrace();
				}
			}
		}

		return flag;


	}

	// This is mine
	// Done 
	// Convert the date from SQL format to Java Format 
	@Override
	public List<Result> getAllResultsForCategory(MathFactsCategory mfc,
			String username) {
		List<Result> results = new ArrayList<Result>();
		
		ResultSet result = null;
		List<Integer> result_id = new ArrayList<Integer>();
		String query = "select user_id from users where login_name = '" + username + "'";
		int user_id = -1;

		try{
			
			result = statement.executeQuery(query);
			if(result.next()){
				user_id = result.getInt("user_id");

			}

			if(user_id != -1){
				query = "select result_id from users_has_results where user_id = "+ user_id+ "";
				result = statement.executeQuery(query);
				int i =0;
				while(result.next()){
					result_id.add(result.getInt("result_id"));

					i++;
				}
			}
		}catch (SQLException e){
			e.printStackTrace();
		}

		//use this category name to search the database category
		String categoryname = mfc.toString();
		int category_id = -1;
		//TODO: create a result for each row returned for a categoryname and username
		if( categoryname.equalsIgnoreCase("Addition")){
			category_id = 1;
		}else if( categoryname.equalsIgnoreCase("Subtraction")){
			category_id = 2;
		}else if( categoryname.equalsIgnoreCase("Multiplication I")){
			category_id = 3;
		}else if(categoryname.equalsIgnoreCase("Multiplication II")){
			category_id = 4;
		}else if( categoryname.equalsIgnoreCase("Division")){
			category_id = 5;
		}else if( categoryname.equalsIgnoreCase("Fractions to Decimals")){
			category_id = 6;
		}
		String date1 = null;
		int countIncorrect=-1;
		int	total =-1;
		Date date = null;
		Result r= null;


		for(int i=0; i<result_id.size();i++){
			try {
				query ="select correct,date,total from results where category_id = "+ category_id +" and result_id = " + result_id.get(i);
				result = statement.executeQuery(query);
				if(result.next()){
					total = result.getInt("total");
					countIncorrect = total - result.getInt("correct"); 
					date1 = result.getString("date");
					date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date1);
				}
				if(date != null && total != -1 && countIncorrect != -1){
					r = new Result(countIncorrect,total, username,mfc, date);
					results.add(r);
				}
			} catch (SQLException e) {

				e.printStackTrace();
			}catch(ParseException e1){
				e1.printStackTrace();
			}	
		}
		return results;
	}

	// Done 
	@Override
	public boolean addIncorrectEquationResult(Problem p, String username) {
		// Check to see if the problem is already in the database of incorrect problems for a given username
		// if it is, then simply increment the count for that problem. If it isn't
		// then add a new row with the given equation and username and a count of 1


		boolean flag = false;
		
		ResultSet result = null;

		if(!this.usernameAvailable(username)) {
			String query = "select user_id from users where login_name = '" + username + "'";
			int user_id = -1;
			int equations_id = -1;
			int number_of_wrongs = -1;

			try{
				
				result = statement.executeQuery(query);
				if(result.next()){
					user_id = result.getInt("user_id");

				}
				if(user_id != -1){
					query = "select equations_id from equations where equation = '" + p.getEquation() + "'";

					result = statement.executeQuery(query);
					if(result.next()){
						equations_id = result.getInt("equations_id");
					}
					if(equations_id != -1){
						query = "select number_of_wrongs from incorrect_answers where user_id = " + user_id + " and equations_id = " + equations_id +"";
						result = statement.executeQuery(query);
						if(result.next()){
							number_of_wrongs = result.getInt("number_of_wrongs");
						}

						if(number_of_wrongs != -1){
							// Means the user already exists and update his record
							number_of_wrongs++;
							query = "update incorrect_answers set number_of_wrongs = "+ number_of_wrongs +" where user_id ="+ user_id +" and  equations_id = "+ equations_id +" ";
							statement.executeUpdate(query);


							flag = true;
						}else {
							// Create a new record for this user with the given equation
							number_of_wrongs = 1;
							query = "insert into incorrect_answers (user_id, equations_id, number_of_wrongs) values ("+ user_id + " , "+ equations_id+ "," + number_of_wrongs+" )";
							statement.executeUpdate(query);

							flag = true;
						}

					}
				}
			}catch(SQLException e){
				e.printStackTrace();
			}finally {
				try {
					if(statement != null && result != null) {
						
						result.close();
					}
				}catch(SQLException e) {
					e.printStackTrace();
				}
			}
		}

		//obviously return false if unsuccessfull, true if successful
		return flag;
	}

	@Override
	public List<IncorrectProblemStatistic> getIncorrectProblemsStatistics(
			String username) {

		List<IncorrectProblemStatistic> probStats = new ArrayList<IncorrectProblemStatistic>();
		// TODO Query the table of incorrect problems, populate the returned rows
		//into "IncorrectProblemStatistic" objects, and add them to an arraylist
		//of IncorrectProblemStatistics. 

		if(!this.usernameAvailable(username)) {

			//
			String query = "select equation, solution, number_of_wrongs, e.category_id " +
					"from users u, incorrect_answers ia, equations e " +
					"where u.login_name = '" + username + "' " + 
					"and u.user_id = ia.user_id " +
					"and ia.equations_id = e.equations_id";

			
			ResultSet result = null;
			Problem p = null;
			IncorrectProblemStatistic ips = null;
			String equation = "";
			String solution = "";
			int number_of_wrongs = -1;
			int category_id = -1;

			try {
				
				result = statement.executeQuery(query);

				while(result.next()) {
					equation = result.getString("equation");
					solution = result.getString("solution");
					number_of_wrongs = result.getInt("number_of_wrongs");
					category_id = result.getInt("category_id");

					if(category_id == 6) {
						p  = new Problem(equation + " = 0.", solution);
					} else {
						p = new Problem(equation + " = ", solution);
					}

					ips = new IncorrectProblemStatistic(p,number_of_wrongs);
					probStats.add(ips);
				}
			}catch(SQLException e) {
				e.printStackTrace();
			}finally {
				try {
					if(statement != null && result != null) {
						
						result.close();
					}
				}catch(SQLException e) {
					e.printStackTrace();
				}
			}
		}


		return probStats;
	}

	@Override
	public boolean usernameAvailable(String username) {

		String query = "select login_name from users where login_name = '"+ username + "'";
		
		ResultSet result = null;

		try {
			statement = connection.createStatement();
			result = statement.executeQuery(query);
			if(!(result.next())){
				return true;
			} else {
				return false;
			}
		} catch (SQLException e) {
			// print the stack
			e.printStackTrace();
		}finally {
			try {
				if(statement != null && result != null) {
					
					result.close();
				}
			}catch(SQLException e) {
				e.printStackTrace();
			}
		}


		return false;
	}

	@Override
	public boolean deleteAccount(Account deleter, String username) {

		boolean exists = this.usernameAvailable(username);
		
		ResultSet result = null;
		int user_id = -1;
		List<Integer> result_id = new ArrayList<Integer>();

		if(deleter instanceof Admin && !(exists) ){

			String query = "delete from users where login_name = '" + username +"'";
			String query2 = "select user_id from users where login_name = '"+ username +"'";
			String query3 = null;

			try {
				
				result = statement.executeQuery(query2);
				if((result.next())) {
					user_id  = result.getInt("user_id");

					if(user_id != -1){
						query3 = "select result_id from users_has_results where user_id = " + user_id +" ";
						result = statement.executeQuery(query3);

						while(result.next()){

							result_id.add(result.getInt("result_id"));

						}
						query3 = "delete from users_has_results where user_id =" + user_id +"";
						statement.executeUpdate(query3);

						query3 = "delete from users_has_privileges where user_id =" + user_id +"";
						statement.executeUpdate(query3);

						query3 = "delete from incorrect_answers where user_id =" + user_id +"";
						statement.executeUpdate(query3);

						for(int i=0; i<result_id.size();i++){
							query3 = "delete from results where result_id = "+ result_id.get(i)+ "";
							statement.executeUpdate(query3);
						}
					}
				}
				statement.executeUpdate(query);

			} catch (SQLException e) {
				// print the stack
				e.printStackTrace();
			}finally {
				try {
					if(statement != null && result != null) {
						
						result.close();
					}
				}catch(SQLException e) {
					e.printStackTrace();
				}
			}
			return true;
		}else{
			return false;
		}
	}


	@Override
	public boolean changePassword(Account changer, String username,
			String newPassword) {
		boolean changed = true;
		//only change password if username is available, the changer is an instructor or admin
		if((!this.usernameAvailable(username)) && (changer instanceof Instructor || changer instanceof Admin)){
			String query = "update users set password = '"+ newPassword + "' where login_name = '" + username +"'";
			
			try{
				
				statement.executeUpdate(query);
				changed = false;
			} catch (SQLException e) {
				// print the stack
				e.printStackTrace();
			} 
		}
		return changed;
	}

	@Override
	public List<Result> getAllResults(String username) {

		List<Result> results = new ArrayList<Result>();

		
		//TODO: Replace these stubs with actual results taken from the database.
		// you will have to initialize real math facts categories every time you create
		//a new result. You can get the category type, the username, incorrect scores, total, 
		//and date from the database. Add these results to the list and return the list.

		if(!this.usernameAvailable(username)) {
			Result r = null;
			
			ResultSet result = null;
			String date1 = "";
			int correct = -1;
			int total_questions = -1;
			MathFactsCategory mfc = null;
			int category_id = -1;
			Date date = null;
			String query = "select correct, date, total, category_id " +
					"from users u, users_has_results uhr, results r " +
					"where login_name = '" + username + "' " +  
					"and u.user_id = uhr.user_id " +
					"and uhr.result_id = r.result_id";


			try {
				
				result  = statement.executeQuery(query);

				while(result.next()) {
					correct = result.getInt("correct");
					date1 = result.getString("date");
					total_questions = result.getInt("total");
					category_id = result.getInt("category_id");

					date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date1);

					if(category_id == 1) {
						mfc = new Addition();
					} else if (category_id == 2) {
						mfc = new Subtraction();
					} else if (category_id == 3) {
						mfc = new Multiplication1();
					} else if (category_id == 4) {
						mfc = new Multiplication2();
					} else if (category_id == 5) {
						mfc = new Division();
					} else if (category_id == 6) {
						mfc = new FractionToDecimal();
					}

					r = new Result(total_questions - correct,total_questions,username,mfc,date);
					results.add(r);
				}
			}catch(SQLException e) {
				e.printStackTrace();
			}catch(ParseException e) {

			}finally {
				try {
					if(statement != null && result != null) {
						
						result.close();
					}
				}catch(SQLException e) {
					e.printStackTrace();
				}
			}		
		}


		return results;

	}


	@Override
	public MathFactsCategory getAllEquationsForCategory(String categoryname) {
		//Initialize a mathfacts category as taken from the database 
		MathFactsCategory mfc1 = new Addition();
		MathFactsCategory mfc2 = new Multiplication1();
		MathFactsCategory mfc3 = new Multiplication2();
		MathFactsCategory mfc4 = new Division();
		MathFactsCategory mfc5 = new Subtraction();
		MathFactsCategory mfc6 = new FractionToDecimal();


		List<Problem> problems1 = new ArrayList<Problem>();
		List<Problem> problems2 = new ArrayList<Problem>();
		List<Problem> problems3 = new ArrayList<Problem>();
		List<Problem> problems4 = new ArrayList<Problem>();
		List<Problem> problems5 = new ArrayList<Problem>();
		List<Problem> problems6 = new ArrayList<Problem>();
		List<Problem> problems7 = new ArrayList<Problem>();
		List<Problem> problems8 = new ArrayList<Problem>();
		List<Problem> problems9 = new ArrayList<Problem>();

		int category_id = -1;

		if(categoryname.equals("Addition")) {
			category_id = 1;
		} else if(categoryname.equals("Subtraction")) {
			category_id = 2;
		} else if(categoryname.equals("Multiplication I")) {
			category_id = 3;
		} else if(categoryname.equals("Multiplication II")) {
			category_id = 4;
		} else if(categoryname.equals("Division")) {
			category_id = 5;
		} else if(categoryname.equals("Fractions to Decimals")) {
			category_id = 6;
		}

		String query = "select set_id, equation, solution from equations where category_id= '" + category_id + "' order by set_id";

		
		ResultSet result = null;

		try {
			
			result = statement.executeQuery(query);
			int set_id =0;
			String equation = "";
			String solution = "";
			Problem problem = null;


			while(result.next()) {

				set_id = result.getInt("set_id");
				equation = result.getString("equation");
				solution = result.getString("solution");
				solution = solution.trim();


				if(category_id == 6){
					problem = new Problem ((equation+ " = 0."), solution);
				}else{
					problem = new Problem ((equation+ " = "),solution);
				}

				if(set_id == 1){
					problems1.add(problem);
				}else if(set_id == 2){

					problems2.add(problem);
				}else if(set_id == 3){

					problems3.add(problem);
				}else if(set_id == 4){

					problems4.add(problem);
				}else if(set_id == 5){

					problems5.add(problem);
				}else if(set_id == 6){

					problems6.add(problem);
				}else if(set_id == 7){

					problems7.add(problem);
				}else if(set_id == 8){

					problems8.add(problem);
				}else if(set_id == 9){

					problems9.add(problem);
				}

			}
		}catch(SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				
				result.close();
			}catch(SQLException e) {
				e.printStackTrace();
			}
		}


		if(categoryname.equals(mfc1.toString())){

			mfc1.setProblem1(problems1);
			mfc1.setProblem2(problems2);
			mfc1.setProblem3(problems3);
			mfc1.setProblem4(problems4);
			mfc1.setProblem5(problems5);
			mfc1.setProblem6(problems6);
			mfc1.setProblem7(problems7);
			mfc1.setProblem8(problems8);
			mfc1.setProblem9(problems9);
			return mfc1;
		}else if(categoryname.equals(mfc2.toString())){
			mfc2.setProblem1(problems1);
			mfc2.setProblem2(problems2);
			mfc2.setProblem3(problems3);
			mfc2.setProblem4(problems4);
			mfc2.setProblem5(problems5);
			mfc2.setProblem6(problems6);
			mfc2.setProblem7(problems7);
			mfc2.setProblem8(problems8);
			mfc2.setProblem9(problems9);
			return mfc2;
		} else if(categoryname.equals(mfc3.toString())){
			mfc3.setProblem1(problems1);
			mfc3.setProblem2(problems2);
			mfc3.setProblem3(problems3);
			mfc3.setProblem4(problems4);
			mfc3.setProblem5(problems5);
			mfc3.setProblem6(problems6);
			mfc3.setProblem7(problems7);
			mfc3.setProblem8(problems8);
			mfc3.setProblem9(problems9);
			return mfc3;
		} else if(categoryname.equals(mfc4.toString())){
			mfc4.setProblem1(problems1);
			mfc4.setProblem2(problems2);
			mfc4.setProblem3(problems3);
			mfc4.setProblem4(problems4);
			mfc4.setProblem5(problems5);
			mfc4.setProblem6(problems6);
			mfc4.setProblem7(problems7);
			mfc4.setProblem8(problems8);
			mfc4.setProblem9(problems9);
			return mfc4;
		} else if(categoryname.equals(mfc5.toString())){
			mfc5.setProblem1(problems1);
			mfc5.setProblem2(problems2);
			mfc5.setProblem3(problems3);
			mfc5.setProblem4(problems4);
			mfc5.setProblem5(problems5);
			mfc5.setProblem6(problems6);
			mfc5.setProblem7(problems7);
			mfc5.setProblem8(problems8);
			mfc5.setProblem9(problems9);
			return mfc5;
		} else if(categoryname.equals(mfc6.toString())){
			mfc6.setProblem1(problems1);
			mfc6.setProblem2(problems2);
			mfc6.setProblem3(problems3);
			mfc6.setProblem4(problems4);
			mfc6.setProblem5(problems5);
			mfc6.setProblem6(problems6);
			mfc6.setProblem7(problems7);
			mfc6.setProblem8(problems8);
			mfc6.setProblem9(problems9);
			return mfc6;
		} 

		return null;

	}

}
